using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using Manoli.Utils.CSharpFormat;
public partial class TreeSource : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string [] files = Directory.GetFiles(Server.MapPath("."));
        GridControl.TreeNode node;
        node = new GridControl.TreeNode();
        node.id = "root";
        node.IsRoot = true;
        node.text = "";
        node.leaf = true;
        TreeFile.TreeNodes.Add(node);
        foreach (string file in files)
        {
            string extension=Path.GetExtension(file);
            if (extension==".aspx" || extension==".cs")
            {
                  node = new GridControl.TreeNode();
                  node.id = Path.GetFileName(file);
                  node.text = Path.GetFileName(file);
                  node.parentNodeId = "root";
                  node.leaf = true;
                  TreeFile.TreeNodes.Add(node);
            }
          
        }

    }

    protected void TreeFile_NodeClicked(object sender, GridControl.NodeClickedEventArgs e)
    {
        string fileName = e.NodeClicked.text;
        System.IO.StreamReader read = new System.IO.StreamReader(Server.MapPath(fileName));
        string source = read.ReadToEnd();
        read.Close();
        read.Dispose();
        
        //LiteralControl ltl= new LiteralControl();
        if (fileName.IndexOf("aspx") != -1)
        {
            CSharpFormat format = new CSharpFormat();
            source_code.InnerHtml = format.FormatCode(source);
        }
        else
        {
            HtmlFormat htmformat = new HtmlFormat();
            source_code.InnerHtml = htmformat.FormatCode(source);
           
        }
        Label1.Text = e.NodeClicked.text;
    }
}
